package com.dongdongshop.controller;

import com.dongdongshop.common.AjaxResult;
import com.dongdongshop.common.PageResult;
import com.dongdongshop.common.ResultEnum;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.TbBrandService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("brand")
public class BrandController {

    Logger logger = LoggerFactory.getLogger(BrandController.class);

    @DubboReference
    private TbBrandService tbBrandService;

    /*品牌管理页面跳转*/
    @RequestMapping("runBrand")
    public String runSeller(){
        return "admin/brand";
    }
    /*品牌管理页面展示*/
    @RequestMapping("selectInfoLimitServer")
    @ResponseBody
    public PageResult<TbBrand> selectInfoLimitServer(TbBrand brand, @RequestParam(value = "pageNumber",defaultValue = "1") Integer pageNumber,
                                                     @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize) {
        PageResult<TbBrand> pageBean = tbBrandService.selectInfoLimitServer(brand,pageNumber, pageSize);
        return pageBean;
    }
    /*添加品牌*/
    @RequestMapping("addBrand")
    @ResponseBody
    public AjaxResult addBrand(TbBrand brand){
        try {
            int i   = tbBrandService.addBrand(brand);
            if (i>0){
                return AjaxResult.R(ResultEnum.SUCCESS);
            }
            return AjaxResult.R(ResultEnum.ERROR);
        }catch (Exception e){
            logger.error("品牌添加失败!错误详情:{}",e);
            return AjaxResult.R(ResultEnum.ERROR);
        }
    }

}
